public class Complex {

    double R;

    double I;



    Complex(double R, double I) {

        this.R = R;

        this.I = I;

    }



    public static double getRealPart(double R) {

        return R;

    }



    public static double getImagePart(double I) {

        return I;

    }



    public Complex ComplexAdd(Complex c) {

        return new Complex(R + c.R, I + c.I);

    }



    public Complex ComplexSub(Complex c) {

        return new Complex(R - c.R, I - c.I);

    }



    public Complex ComplexMulti(Complex c) {

        return new Complex(R * c.R - I * c.I, R * c.I + I * c.R);

    }



    public Complex ComplexDiv(Complex c) {

        return new Complex((R * c.I + I * c.R) / (c.I * c.I + c.R * c.R), (I * c.I + R * c.R) / (c.I * c.I + c.R * c.R));

    }



    public String toString() {

        String str = "";

        if (I > 0)

            str = R + "+" + I + "i";

        if (I == 0)

            str = R+"";

        if (I < 0)

            str = R + "" + I + "i";

        return str;

    }

    public boolean equals(Object obj){

        if (this == obj)

            return true;

        if(obj==null)

            return false;

        if(obj instanceof Complex){

            Complex p = (Complex) obj;

            if(p.R==this.R &&p.I==this.I )

                return true;

        }

        return false;

    }

}
